package com.yang.smsgateway.config;

import cn.hippo4j.core.executor.DynamicThreadPool;
import cn.hippo4j.core.executor.support.ThreadPoolBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.ThreadPoolExecutor;

@Configuration
public class ThreadPoolConfig {

    @Bean
    @DynamicThreadPool
    public ThreadPoolExecutor cmppSubmitPool(){
        //cmpp的submit响应
        String threadPoolId = "cmpp-submit";
        ThreadPoolExecutor messageConsumeDynamicExecutor = ThreadPoolBuilder.builder()
                // 指定线程名称的前缀
                .threadFactory(threadPoolId)
                // 线程池在Hippo4j中的唯一标识
                .threadPoolId(threadPoolId)
                // 代表动态线程池，随时调整线程池的核心参数
                .dynamicPool()
                .build();
        return messageConsumeDynamicExecutor;
    }

    @Bean
    @DynamicThreadPool
    public ThreadPoolExecutor cmppDeliverPool(){
        //cmpp的deliver响应
        String threadPoolId = "cmpp-deliver";
        ThreadPoolExecutor messageConsumeDynamicExecutor = ThreadPoolBuilder.builder()
                // 指定线程名称的前缀
                .threadFactory(threadPoolId)
                // 线程池在Hippo4j中的唯一标识
                .threadPoolId(threadPoolId)
                // 代表动态线程池
                .dynamicPool()
                .build();
        return messageConsumeDynamicExecutor;
    }

    /*
     * 补充基础知识：Bean注解可以定义一个bean，并且可以通过@Bean注解的name属性来指定bean的名称。
     * 如果不指定`name`属性，则bean的名称默认是方法名。
     */
}
